#pragma once
#include "Rectangle.h"
#include "Color.h"
#include <iostream>

extern unsigned char ttu[];
extern int ttunumber;
extern unsigned char zzhi[];
extern int zzhinumber;

namespace qing {
	class Drawable {
		public:
			// 该枚举类型用于表示旋转方向
			// 该类型还未应用
			// 使用static_cast<Rotate> ()
			enum class Rotate: char {
				R_0 = 0,
				R_90 = 1,
				R_180 = 2,
				R_270 = 3
			};

			// attr 属性区
			Drawable(int w, int h, int x, int y, int rotate, int fontsize);
			virtual Rectangle get_size();
			virtual Rectangle get_pos();
			virtual void set_pos(Rectangle rect);
			virtual Color get_color(int x, int y);
			virtual void set_color(Color &color);
			void FontSize(int fontsize);
			int FontSize_get();
			virtual Color& getFontsColor();
			// basic 基本
			virtual Color _get(int x, int y) = 0;
			virtual void _p(int x, int y, Color &clr) = 0;
			virtual void _up(int x, int y, int w, int h, int level) = 0;
			virtual void _down(int x, int y, int w, int h, int level) = 0;
			virtual void _left(int x, int y, int w, int h, int level) = 0;
			virtual void _right(int x, int y, int w, int h, int level) = 0;
			//virtual void _clear(int x, int y, int w, int h) = 0;
			// drawer 绘制
			virtual void point(int x, int y, Color &clr);
			virtual void line(int x1, int y1, int x2, int y2, Color &clr);
			virtual void rectangle(int x, int y, int w, int h, Color &clr);
			virtual void rectangle_fill(int x, int y, int w, int h, Color &clr);
			virtual void up(int x, int y, int w, int h, int level);
			virtual void down(int x, int y, int w, int h, int level);
			virtual void left(int x, int y, int w, int h, int level);
			virtual void right(int x, int y, int w, int h, int level);
			virtual void flush(Drawable *n, bool border) = 0;
			// printer 打印
			void drawvfont(int x, int y, unsigned short z, Color &clr);
			// test 测试
			virtual void test();
			virtual void test1();

			/* 非法的旋转模式 */
			class InvalidRotateMode: std::runtime_error {
				public:
					InvalidRotateMode(): std::runtime_error("Invalid rotate mode.") {}
			};

		protected:
			// window
			int w, h, x, y, rotate=0;
			// fonts lib
			int font_w, font_h;
			unsigned short *chss = (unsigned short *)zzhi;
			unsigned char *vec = ttu;
			int zn;
			int vennum;
			unsigned char *drawvect(int x, int y, unsigned char *vect, int width, int high, Color &clr);
			// printer
			//Color clr = green;
			Color clr = white;
	};
}
